//
//  HeaderCollectionReusableView.m
//  BigJoy
//
//  Created by new-1020 on 2017/6/13.
//  Copyright © 2017年 Rowling. All rights reserved.
//

#import "HeaderCollectionReusableView.h"
#import "SDCycleScrollView.h"
#import "HeaderCollectionViewCell.h"
#import "ShowMoreCell.h"
#import "indexDesignerListVC.h"
#import "DesignerDetailViewController.h"

@interface HeaderCollectionReusableView()<SDCycleScrollViewDelegate,UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
@property (weak, nonatomic) IBOutlet UIView *headCycleView;
@property (weak, nonatomic) IBOutlet UIView *bottomCollectionView;
@property (nonatomic,strong) SDCycleScrollView *cycleView;
@property (nonatomic,strong) UICollectionView *collectionView;
@property (nonatomic,strong) UICollectionViewFlowLayout *layout;
@end

@implementation HeaderCollectionReusableView

- (void)awakeFromNib {
    [super awakeFromNib];
    // cycleView
    [self.headCycleView addSubview:self.cycleView];
    [self.cycleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.bottom.equalTo(self.headCycleView);
    }];
    self.cycleView.localizationImageNamesGroup = @[@"1.jpeg",@"2.jpeg",@"test.jpg"];
    
    //collectionView
    [self.bottomCollectionView addSubview:self.collectionView];
    [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.top.equalTo(self.bottomCollectionView);
    }];
    [self.bottomCollectionView layoutIfNeeded];
    [self.collectionView layoutIfNeeded];
    _collectionView.delegate = self;
    _collectionView.dataSource = self;
    _collectionView.backgroundColor = [UIColor whiteColor];
    [_collectionView registerNib:[UINib nibWithNibName:@"HeaderCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"Cell"];
    [_collectionView registerNib:[UINib nibWithNibName:NSStringFromClass([ShowMoreCell class]) bundle:nil] forCellWithReuseIdentifier:@"ShowCell"];
    
}

-(SDCycleScrollView *)cycleView {
    if(_cycleView == nil) {
        _cycleView = [[SDCycleScrollView alloc]init];
        _cycleView.delegate = self;
        _cycleView.autoScrollTimeInterval = 4;
        _cycleView.bannerImageViewContentMode = 2;
        _cycleView.backgroundColor = [UIColor whiteColor];
//        _cycleView.pageControlAliment = SDCycleScrollViewPageContolAlimentRight;
        _cycleView.pageDotColor = [UIColor clearColor];
        _cycleView.currentPageDotColor = [UIColor whiteColor];
    }
    return  _cycleView;
}

/** 点击图片回调 */
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index {
}

//collectionView
-(UICollectionView *)collectionView {
    if (_collectionView == nil) {
        UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayout alloc]init];
        layout.minimumInteritemSpacing = XMH(10);
        layout.sectionInset = UIEdgeInsetsMake(0, XMW(10), 0, XMW(10));
        layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        self.layout = layout;
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT - 64) collectionViewLayout:layout];
        _collectionView.showsHorizontalScrollIndicator = NO;
    }
    return _collectionView;
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 10;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    HeaderCollectionViewCell * cell  = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
    cell.data = [NSDictionary dictionary];
    return cell;
}

-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    [collectionView layoutIfNeeded];
    return CGSizeMake(150, 105);
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    DesignerDetailViewController * vc = [DesignerDetailViewController new];
    [[XMSuperHelper XMControllerOfView:self].navigationController pushViewController:vc animated:YES];
}
// 查看更多
- (IBAction)moreButtonClick:(id)sender {
        // showMoreCell clicked
        indexDesignerListVC * vc = [[indexDesignerListVC alloc]init];
        [[XMSuperHelper XMControllerOfView:self].navigationController pushViewController:vc animated:YES];
}


@end
